package com.gitee.loyo.jdbc

import java.math.BigDecimal
import java.sql.Date
import java.sql.Time
import java.sql.Timestamp
import java.sql.Types
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime

object TypeMapping {

    fun toJavaType(sqlType: Int): Class<*>{
        var result: Class<*> = Any::class.java

        when (sqlType) {
            Types.CHAR, Types.VARCHAR, Types.LONGVARCHAR -> result = String::class.java
            Types.NUMERIC, Types.DECIMAL -> result = BigDecimal::class.java
            Types.BIT -> result = Boolean::class.java
            Types.TINYINT -> result = Boolean::class.java
            Types.SMALLINT -> result = Short::class.java
            Types.INTEGER -> result = Int::class.java
            Types.BIGINT -> result = Long::class.java
            Types.REAL, Types.FLOAT -> result = Float::class.java
            Types.DOUBLE -> result = Double::class.java
            Types.BINARY, Types.VARBINARY, Types.LONGVARBINARY -> result = Array<Byte>::class.java
            Types.DATE -> result = LocalDate::class.java
            Types.TIME -> result = LocalTime::class.java
            Types.TIMESTAMP -> result = LocalDateTime::class.java
        }

        return result!!
    }
}